<%-- 
    Document   : addStudent
    Created on : Dec 19, 2014, 1:22:07 PM
    Author     : DucND
--%>
<%@page import="dao.StudentDAO"%>
<%@page import="entity.Student"%>
<jsp:include page="../header.jsp"></jsp:include>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
    String studentID;
    int age = 0;
    String gender;
    String image;
    String name;
    String address;
    String batch;
    String email;
    
    String addBtn = request.getParameter("addBtn");
    if (addBtn != null) {
        studentID = request.getParameter("studentID");
        name = request.getParameter("name");
        String ageString = request.getParameter("age");
        try {
            age = Integer.parseInt(ageString);
        } catch (Exception e) {}
        address = request.getParameter("address");
        gender = request.getParameter("gender");
        batch = request.getParameter("batch");
        image = request.getParameter("image");
        
        Student st = new Student(studentID, name, age, address, gender.charAt(0), batch, image);
        StudentDAO.AddStudent(st);
        response.sendRedirect("listStudent.jsp");
    }
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Add Student</title>
    </head>
    <body>
        <div class="container">
            <h2>Add new Student</h2>
            <hr>
            <form action="addStudent.jsp" method="POST">
                <table width="50%" style="border-collapse: separate; border-spacing: 20px">
                    <tr>
                        <td width="30%">&nbsp;</td>
                        <td width="70%">&nbsp;</td>
                    </tr>

                    <tr>
                        <td>Student ID(<font color="red">*</font>) </td>
                        <td><input name="studentID" type="text" class="form-control" required/></td>
                    </tr>
                    <tr>
                        <td>Name(<font color="red">*</font>) </td>
                        <td><input name="name" type="text" class="form-control" required/></td>
                    </tr>
                    <tr>
                        <td>Age(<font color="red">*</font>) </td>
                        <td><input name="age"  type="number" class="form-control" required/></td>                      
                    </tr>
                    <tr>
                        <td>Address(<font color="red">*</font>) </td>
                        <td><input name="address" type="text"  class="form-control" required/></td>
                    </tr>
                    <tr>
                        <td>Gender(<font color="red">*</font>) </td>
                        <td>
                            <input type="radio" name="gender" value="M" <%//if (gender != null && gender.equals("M")) {%> checked="" <%//}%>/> Male
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="radio" name="gender" value="F" <%//if (gender != null && gender.equals("F")) {%> checked="" <%//}%>/> Female
                        </td>
                    </tr>
                    <tr>
                        <td>Batch(<font color="red">*</font>) </td>
                        <td><input name="batch" type="text" class="form-control" required/></td>
                    </tr>
                    <tr>
                        <td>Image(<font color="red">*</font>) </td>
                        <td><input name="image" type="text" class="form-control" required/></td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td><input name="addBtn" type="submit" value="Add" class="btn btn-success" style="width: 100px"/></td>
                        <td><a href="listStudent.jsp"><input type="button" value="Cancel" class="btn btn-danger" style="width: 100px"/></a></td>
                    </tr>
                </table>
            </form>
        </div>
    </body>
</html>
<jsp:include page="../footer.jsp"></jsp:include>